package FilePackage;
import java.util.*;
import java.io.*;
public class File_Directory {
	//main procedure
	public static void main (String[] arg){
		Scanner scanner=new Scanner (System.in);
		
		System.out.println("Enter directory: ");
		String Path=scanner.nextLine();	
		File Directory = new File(Path);
		
		if (Directory.exists()){
		System.out.println("Enter the mask");
		String Mask = scanner.nextLine();
		searchFiles(Directory,Mask);
		}
		else System.out.println("Directory is not found...");
	}
	//recursive procedure to check the contents of a directory
	public static void searchFiles(File Directory,String Mask)
	{
		if (Directory.isFile()) getInfoFile(Directory,Mask);
		else {
			getInfoFile(Directory,Mask);
			File[] SubDirectory = Directory.listFiles();
			for (File SubWay:SubDirectory)
				searchFiles(SubWay,Mask);
		}
	}
	//display information about the file, if the mask is contained in its name
	public static void getInfoFile(File Object,String Mask){
			String Name = Object.getName();
			
			if (Name.contains(Mask)) {
				System.out.println(Object.getPath()+"\n"+ Name + "\n" 
						+ new Date(Object.lastModified())+"\n");				
			}
		}
}
